package com.et.u2.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.RectF
import android.util.AttributeSet
import android.util.Log
import android.util.TypedValue
import android.view.View
import java.util.*

data class Bubble(var radius: Int, var speedX: Int, var speedY: Int, var x: Float, var y: Float)

class BubbleView : View {

    private val rootRectF = RectF()

    constructor(context: Context) : this(context, null)

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int = 0) : super(
        context,
        attrs,
        defStyleAttr
    ) {


    }


    override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
        super.onSizeChanged(w, h, oldw, oldh)
        Log.d("et_log", "onSizeChanged  $w  $h  $oldw  $oldh")
        rootRectF.left = paddingLeft.toFloat()
        rootRectF.right = (w - paddingRight).toFloat()
        rootRectF.top = paddingTop + 300f
        rootRectF.bottom = h - paddingBottom + 300f
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)

    }

    private fun dp2px(dpValue: Float): Float {
        return TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP,
            dpValue,
            resources.displayMetrics
        )
    }

    companion object {
        private val random = Random()

    }
}